#pragma once

#include <gofcl_rcu_r.h>

typedef struct {
	u8_s IRC8MEN : 1;
	u8_s IRC8MSTB : 1;
	u8_s : 1;
	u8_s IRC8MADJ : 5;
} rcu_ctl_0_7_s;

_Static_assert(sizeof(rcu_ctl_0_7_s) == 1,
	       "Struct rcu_ctl_0_7_s defined error!");

static inline void rcu_wreg_ctl_0_7_s(rcu_ctl_0_7_s ctl_0_7) {
	union {
		rcu_ctl_0_7_s c;
		u8_s u;
	} cu = {
		.c = ctl_0_7,
	};
	rcu_wreg_u8(RCU_CTL_R, T8B_0_R, cu.u);
}

static inline rcu_ctl_0_7_s rcu_rreg_ctl_0_7_s(void) {
	union {
		rcu_ctl_0_7_s c;
		u8_s u;
	} cu = {
		.u = rcu_rreg_u8(RCU_CTL_R, T8B_0_R),
	};
	return cu.c;
}

typedef struct {
	u8_s IRC8MCALIB;
} rcu_ctl_8_15_s;

_Static_assert(sizeof(rcu_ctl_8_15_s) == 1,
	       "Struct rcu_ctl_8_15_s defined error!");

static inline rcu_ctl_8_15_s rcu_rreg_ctl_8_15_s(void) {
	union {
		rcu_ctl_8_15_s c;
		u8_s u;
	} cu = {
		.u = rcu_rreg_u8(RCU_CTL_R, T8B_1_R),
	};
	return cu.c;
}

typedef struct {
	rcu_ctl_0_7_s ctl_0_7;
	rcu_ctl_8_15_s ctl_8_15;
} __attribute__((aligned(2))) rcu_ctl_0_15_s;

_Static_assert(sizeof(rcu_ctl_0_15_s) == 2,
	       "Struct rcu_ctl_0_15_s defined error!");

static inline rcu_ctl_0_15_s rcu_rreg_ctl_0_15_s(void) {
	union {
		rcu_ctl_0_15_s c;
		u16_s u;
	} cu = {
		.u = rcu_rreg_u16(RCU_CTL_R, T16B_0_R),
	};
	return cu.c;
}

typedef struct {
	u8_s HXTALEN : 1;
	u8_s HXTALSTB : 1;
	u8_s HXTALBPS : 1;
	u8_s CKMEN : 1;
	u8_s : 4;
} rcu_ctl_16_23_s;

_Static_assert(sizeof(rcu_ctl_16_23_s) == 1,
	       "Struct rcu_ctl_16_23_s defined error!");

static inline void rcu_wreg_ctl_16_23_s(rcu_ctl_16_23_s ctl_16_23) {
	union {
		rcu_ctl_16_23_s c;
		u8_s u;
	} cu = {
		.c = ctl_16_23,
	};
	rcu_wreg_u8(RCU_CTL_R, T8B_2_R, cu.u);
}

static inline rcu_ctl_16_23_s rcu_rreg_ctl_16_23_s(void) {
	union {
		rcu_ctl_16_23_s c;
		u8_s u;
	} cu = {
		.u = rcu_rreg_u8(RCU_CTL_R, T8B_2_R),
	};
	return cu.c;
}

typedef struct {
	u8_s PLLEN : 1;
	u8_s PLLSTB : 1;
	u8_s PLL1EN : 1;
	u8_s PLL1STB : 1;
	u8_s PLL2EN : 1;
	u8_s PLL2STB : 1;
	u8_s : 2;
} rcu_ctl_24_31_s;

_Static_assert(sizeof(rcu_ctl_24_31_s) == 1,
	       "Struct rcu_ctl_24_31_s defined error!");

static inline void rcu_wreg_ctl_24_31_s(rcu_ctl_24_31_s ctl_24_31) {
	union {
		rcu_ctl_24_31_s c;
		u8_s u;
	} cu = {
		.c = ctl_24_31,
	};
	rcu_wreg_u8(RCU_CTL_R, T8B_3_R, cu.u);
}

static inline rcu_ctl_24_31_s rcu_rreg_ctl_24_31_s(void) {
	union {
		rcu_ctl_24_31_s c;
		u8_s u;
	} cu = {
		.u = rcu_rreg_u8(RCU_CTL_R, T8B_3_R),
	};
	return cu.c;
}

typedef struct {
	rcu_ctl_16_23_s ctl_16_23;
	rcu_ctl_24_31_s ctl_24_31;
} __attribute__((aligned(2))) rcu_ctl_16_31_s;

_Static_assert(sizeof(rcu_ctl_16_31_s) == 2,
	       "Struct rcu_ctl_16_31_s defined error!");

static inline void rcu_wreg_ctl_16_31_s(rcu_ctl_16_31_s ctl_16_31) {
	union {
		rcu_ctl_16_31_s c;
		u16_s u;
	} cu = {
		.c = ctl_16_31,
	};
	rcu_wreg_u16(RCU_CTL_R, T16B_2_R, cu.u);
}

static inline rcu_ctl_16_31_s rcu_rreg_ctl_16_31_s(void) {
	union {
		rcu_ctl_16_31_s c;
		u16_s u;
	} cu = {
		.u = rcu_rreg_u16(RCU_CTL_R, T16B_2_R),
	};
	return cu.c;
}

typedef struct {
	rcu_ctl_0_7_s ctl_0_7;
	rcu_ctl_8_15_s ctl_8_15;
	rcu_ctl_16_23_s ctl_16_23;
	rcu_ctl_24_31_s ctl_24_31;
} __attribute__((aligned(4))) rcu_ctl_s;

_Static_assert(sizeof(rcu_ctl_s) == 4, "Struct rcu_ctl_s defined error!");

static inline void rcu_wreg_ctl_s(rcu_ctl_s ctl) {
	union {
		rcu_ctl_s c;
		u32_s u;
	} cu = {
		.c = ctl,
	};
	rcu_wreg(RCU_CTL_R, cu.u);
}

static inline rcu_ctl_s rcu_rreg_ctl_s(void) {
	union {
		rcu_ctl_s c;
		u32_s u;
	} cu = {
		.u = rcu_rreg(RCU_CTL_R),
	};
	return cu.c;
}
